package study.算法;

import java.util.Scanner;

/**
 * @Author 刘伟涛
 * @Date 2024/3/8 16:48
 **/
public class 二分查找 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};
        int low = 0;
        int high = arr.length - 1;
        System.out.println("请输入");
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int mid = 0;
        while (low <= high){
            mid = (low+high)/2;
            if(arr[mid] == num){
                System.out.println(mid);
                return;
            }else if(arr[mid] > num){
                high = mid-1;
            }else {
                low = mid+1;
            }
        }
        System.out.println("没有找到");
    }
}
